"""
    测试多个df拼接，以最大列（即字段最多）的df进行拼接保留列的顺序
"""
import pandas as pd

df_dic = {}
df_li = []

df2 = pd.DataFrame(
    data={'a': [1, 2], 'c': [3, 4], 'e': [5, 6]}
)
df_dic['df2-' + str(len(df2.columns))] = df2

df3 = pd.DataFrame(
    data={'b': [2, 3], 'c': [3, 4], 'e': [5, 6]}
)
df_dic['df3-' + str(len(df3.columns))] = df3

df1 = pd.DataFrame(
    data={'a': [1, 2, 3], 'b': [2, 3, 4], 'c': [3, 4, 5], 'd': [4, 5, 6], 'e': [5, 6, 7]}
)
df_dic['df1-' + str(len(df1.columns))] = df1

a = max(df_dic.items(), key=lambda x: x[0].split('-')[-1])[0]

for i in df_dic.keys():
    if a == i:
        df_li.insert(0, df_dic[i])
        continue
    df_li.append(df_dic[i])
df = pd.concat(df_li)
print(df)
